//package com.example.springai.school;
//
//import com.example.springai.school.pojo.HotSchoolDetailResponse;
//import io.swagger.v3.oas.annotations.media.Schema;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Description;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.function.Function;
//
//@Configuration(proxyBeanMethods = false)
//public class SchoolQueryTools {
//
//    private static final Logger logger = LoggerFactory.getLogger(SchoolQueryTools.class);
//
//    @Autowired
//    private SchoolService schoolService;
//
//    public record QueryMajorCountRequest(String schoolName) {
//        @Schema(description = "学校名称")
//        public String schoolName() {
//            return schoolName;
//        }
//    }
//    public record AddSchoolRequest(
//            @Schema(description = "学校名称") String schoolName,
//            @Schema(description = "学校地区") String region,
//            @Schema(description = "专业数量") int majorCount,
//            @Schema(description = "学院数量") int collegeCount,
//            @Schema(description = "学校官网") String website
//    ) {}
//    public record QueryCollegeCountRequest(String schoolName) {}
//    public record ReturnPageURLResponse(String url) {}
//    public record QueryMajorCountResponse(int majorCount) {}
//
//    public record QueryCollegeCountResponse(int collegeCount) {}
//
//    @Bean
//    @Description("根据学校名称查询专业数量")
//    public Function<QueryMajorCountRequest, QueryMajorCountResponse> queryMajorCount() {
//        return request -> {
//            try {
//                int count = schoolService.getMajorCount(request.schoolName());
//                return new QueryMajorCountResponse(count);
//            } catch (Exception e) {
//                logger.warn("Failed to query major count for school {}: {}", request.schoolName(), e.getMessage());
//                return new QueryMajorCountResponse(-1);
//            }
//        };
//    }
//
//    @Bean
//    @Description("根据学校名称查询学院数量")
//    public Function<QueryCollegeCountRequest, QueryCollegeCountResponse> queryCollegeCount() {
//        return request -> {
//            try {
//                int count = schoolService.getCollegeCount(request.schoolName());
//                return new QueryCollegeCountResponse(count);
//            } catch (Exception e) {
//                logger.warn("Failed to query college count for school {}: {}", request.schoolName(), e.getMessage());
//                return new QueryCollegeCountResponse(-1);
//            }
//        };
//    }
//
//    @Bean
//    @Description("添加学校信息")
//    public Function<AddSchoolRequest, String> addSchool() {
//        return request -> {
//            try {
//                schoolService.addSchool(
//                        request.schoolName(),
//                        request.region(),
//                        request.majorCount(),
//                        request.collegeCount(),
//                        request.website()
//                );
//                return "学校添加成功!" ;
//            } catch (Exception e) {
//                logger.warn("Failed to add school {}: {}", request.schoolName(), e.getMessage());
//                return "学校添加失败: " + request.schoolName();
//            }
//        };
//    }
//
//    @Bean
//    @Description("根据学校名称查询学校具体官网")
//    public Function<QueryCollegeCountRequest, ReturnPageURLResponse> queryHotSchool() {
//        return request -> {
//            try {
//                return new ReturnPageURLResponse(schoolService.getSchoolName(request.schoolName()));
//            } catch (Exception e) {
//                logger.warn("Failed to query college count for school {}: {}", request.schoolName(), e.getMessage());
//                return new ReturnPageURLResponse("再无法查询到该学校的具体官网");
//            }
//        };
//    }
//}
